package com.lc.qianrenshiye.conn;

import com.zcx.helper.http.AsyCallBack;
import com.zcx.helper.http.note.HttpInlet;

import org.json.JSONArray;
import org.json.JSONObject;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by Administrator on 2016/12/6.
 */
@HttpInlet(Conn.PAYMENT_DISCOUNT)
public class CutPriceListPost extends BaseAsyPost<CutPriceListPost.CutPriceListEntity> {

    public String sid;

    public CutPriceListPost(AsyCallBack<CutPriceListEntity> asyCallBack) {
        super(asyCallBack);
    }

    @Override
    protected CutPriceListEntity parser(JSONObject object) throws Exception {

        if (object.optInt("code") == 200) {

            CutPriceListEntity cutPriceListEntity = new CutPriceListEntity();

            JSONArray percentPriceArray = object.optJSONArray("percent");

            for (int i = 0; i < percentPriceArray.length(); i++) {

                JSONObject percentPriceObject = percentPriceArray.optJSONObject(i);

                PercentPriceEntity percentPriceEntity = new PercentPriceEntity();

                percentPriceEntity.id = percentPriceObject.optString("id");
                percentPriceEntity.type = percentPriceObject.optString("type");
                percentPriceEntity.percent = percentPriceObject.optString("percent");
                percentPriceEntity.state = percentPriceObject.optString("state");

                cutPriceListEntity.percentPriceEntityList.add(percentPriceEntity);
            }

            JSONArray fullCutPriceArray = object.optJSONArray("money");

            for (int i = 0; i < fullCutPriceArray.length(); i++) {

                JSONObject fullCutPriceObject = fullCutPriceArray.optJSONObject(i);

                FullCutPriceEntity fullCutPriceEntity = new FullCutPriceEntity();

                fullCutPriceEntity.id = fullCutPriceObject.optString("id");
                fullCutPriceEntity.type = fullCutPriceObject.optString("type");
                fullCutPriceEntity.money = fullCutPriceObject.optString("money");

                cutPriceListEntity.fullCutPriceEntityList.add(fullCutPriceEntity);
            }

            return cutPriceListEntity;

        }

        TOAST = object.optString("message");

        return null;
    }

    public static class CutPriceListEntity {

        public List<PercentPriceEntity> percentPriceEntityList = new ArrayList<>();
        public List<FullCutPriceEntity> fullCutPriceEntityList = new ArrayList<>();

    }
    public static class PercentPriceEntity {

        public String id, type, percent, state;

    }
    public static class FullCutPriceEntity {

        public String id, type, money;

    }

}
